<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@taglib prefix="rapid" uri="http://www.rapid-framework.org.cn/rapid" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<rapid:override name="frame-header-style">
    <style>
        /*覆盖 layui*/
        .layui-input-block {
            margin:0px 10px;
        }
        .layui-table {
            margin-top: 0;
        }
        .layui-col-md4 {
            padding:10px;
        }
        .layui-col-md8 {
            padding:10px;
        }
        .layui-btn {
            margin: 2px 0!important;
        }
    </style>
</rapid:override>

<rapid:override name="frame-header-script">
    <script type="text/javascript">
        function validateCateGoryName(name) {
            var result = true;
            name = name.trim();
            if(name==""){
                result = false;
                layer.tips('分类名不能为空', '#cateGoryName', {
                    tips: [1, '#FF0033'],
                    time: 3000
                });
            }else{
                onload=$.ajax({
                    url:"category/validateCateGoryName",
                    type:"POST",
                    cache:false,
                    async:false,
                    dataType:"json",
                    contentType:"application/x-www-form-urlencoded",
                    data:{cateGoryName:name},
                    success:function(data){
                        if(data=="-1"){
                            result = false;
                            layer.tips('分类名重复', '#cateGoryName', {
                                tips: [1, '#FF0033'],
                                time: 3000
                            });
                        }
                    }
                });
            }
            return result;
        }
        function validate() {
             var result = true;
             if(validateCateGoryName($('input[name="cateGoryName"]').val())==false){
                 result = false;
             }
             return result;
        }
    </script>
</rapid:override>

<rapid:override name="frame-content">
    <div style="padding:15px;">
    <blockquote class="layui-elem-quote">
        <span class="layui-breadcrumb" lay-separator="/">
              <a href="user/login">首页</a>
              <a href="category">分类列表</a>
              <a><cite>添加分类</cite></a>
        </span>
    </blockquote>
    <div class="layui-row">
    <div class="layui-col-md4">
        <form class="layui-form"  method="post" onsubmit="return validate()" id="myForm" action="category/insertSubmit">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <strong>添加分类</strong>
                </div>
                <div class="layui-input-block">
                    名称 <span style="color: #FF5722; ">*</span>
                    <input type="text" id="cateGoryName" name="cateGoryName" value="${cateGory.cateGoryName}" placeholder="请输入分类名称" autocomplete="off" class="layui-input" >
                </div>
                <br>
                <div class="layui-input-block">
                    父节点 <span style="color: #FF5722; ">*</span>
                    <select name="categoryPid" id="operatorId" class="layui-input" required>
                            <option value="0">无</option>
                        <c:forEach var="c" items="${cateGoryList}">
                            <c:if test="${c.cateGoryPid==0}">
                             <option value="${c.cateGoryId}" <c:if test="${c.cateGoryId==operatorId}">selected</c:if> >${c.cateGoryName}</option>
                            </c:if>
                        </c:forEach>
                    </select>
                </div>
                <br>
                <div class="layui-input-block">
                    分类描述
                    <input type="text" name="categoryDescription" value="${cateGory.cateGoryDescription}" placeholder="请输入分类描述" autocomplete="off" class="layui-input" >
                </div>
                <br>
                <div class="layui-input-block">
                    图标样式
                    <input type="text" name="categoryIcon" value="${cateGory.cateGoryIcon}" placeholder="请输入图标样式,如 fa fa-coffee" autocomplete="off" class="layui-input" >
                </div>
                <br>
                <div class="layui-input-block">
                    <button class="layui-btn" lay-filter="formDemo" type="submit">修改</button>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-col-md8" >
        <table class="layui-table" >
            <colgroup>
                <col width="300">
                <col width="100">
                <col width="100">
                <col width="100">
                <col width="50">
                <col width="50">
            </colgroup>
            <thead>
            <tr>
                <th>名称</th>
                <th>文章数</th>
                <th>操作</th>
                <th>ID</th>
                <th>pid</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="c" items="${cateGoryList}">
                <c:if test="${c.cateGoryPid==0}">
                <tr>
                    <td>
                        <a href="javascript:void(0)">${c.cateGoryName}</a>
                    </td>
                    <td>
                        <a href="javascript:void(0)">${c.articleCount}</a>
                    </td>
                    <td>
                        <a href="category/edit/${c.cateGoryId}" class="layui-btn layui-btn-mini">编辑</a>
                        <c:if test="${c.articleCount==0}">
                            <a href="category/delete/${c.cateGoryId}" class="layui-btn layui-btn-danger layui-btn-mini" onclick="return confirmDelete()">删除</a>
                        </c:if>
                    </td>
                    <td class="cate-parent">${c.cateGoryId}</td>
                    <td>${c.cateGoryPid}</td>
                </tr>
                    <c:forEach var="subc" items="${c.subCateGoryList}">
                        <tr>
                            <td>
                                <a href="javascript:void(0)" >——${subc.cateGoryName}</a>
                            </td>
                            <td>
                                <a href="javascript:void(0)" >${subc.articleCount}</a>
                            </td>
                            <td>
                                <a href="category/edit/${subc.cateGoryId}" class="layui-btn layui-btn-mini">编辑</a>
                                <c:if test="${subc.articleCount==0}">
                                <a href="category/delete/${subc.cateGoryId}" class="layui-btn layui-btn-danger layui-btn-mini" onclick="return confirmDelete()">删除</a>
                                </c:if>
                            </td>
                            <td class="cate-parent">${subc.cateGoryId}</td>
                            <td>${subc.cateGoryPid}</td>
                        </tr>
                    </c:forEach>
                </c:if>
            </c:forEach>
            </tbody>
        </table>
        <blockquote class="layui-elem-quote layui-quote-nm">
            温馨提示：
            <ul>
                <li>分类最多只有两级，一级分类pid=0，二级分类pid=其父节点id</li>
                <li>如果该分类包含文章，将不可删除</li>
            </ul>
        </blockquote>
    </div>
</rapid:override>

<rapid:block name="frame-footer-script">
    <script type="text/javascript">
        var msg = "${msg}";
        if(msg!=""){
            alert(msg);
        }
    </script>
</rapid:block>
<%@include file="../framework.jsp"%>